package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicStockuparea;
import cn.stylefeng.guns.modular.basic.mapper.BasicStockupareaMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicStockupareaParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicStockupareaResult;
import  cn.stylefeng.guns.modular.basic.service.BasicStockupareaService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 备货区表 服务实现类
 */
@Service
public class BasicStockupareaServiceImpl extends ServiceImpl<BasicStockupareaMapper, BasicStockuparea> implements BasicStockupareaService {

    @Override
    public void add(BasicStockupareaParam param){
        BasicStockuparea entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicStockupareaParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicStockupareaParam param){
        BasicStockuparea oldEntity = getOldEntity(param);
        BasicStockuparea newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicStockupareaResult findBySpec(BasicStockupareaParam param){
        return null;
    }

    @Override
    public List<BasicStockupareaResult> findListBySpec(BasicStockupareaParam param,String condition,Long deptId,Long operateId){
        return this.baseMapper.customList(param,condition,deptId, operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicStockupareaParam param,String condition,Long deptId,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,deptId, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicStockupareaParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicStockuparea getOldEntity(BasicStockupareaParam param) {
        return this.getById(getKey(param));
    }

    private BasicStockuparea getEntity(BasicStockupareaParam param) {
        BasicStockuparea entity = new BasicStockuparea();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
